
package com.mephi.gui;


import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RadialGradientPaint;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import javax.swing.JButton;


/**
 * 
 * This class extends javax.swing.JButton 
 * @since 2011-04-09
 */
public class HighlightedButton extends JButton 
{  
	/**
	 * 
	 * It creates a new instance of HighlightedButton 
	 * @param label the label to set
	 */
    public HighlightedButton(String label)
    {
        super(label);
        
        // Get the Graphics for the image
        Graphics2D g2d = highlight.createGraphics();
        
        // Erase the image with a transparent background
        g2d.setComposite(AlphaComposite.Clear);
        g2d.fillRect(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE);
        g2d.setComposite(AlphaComposite.SrcOver);
        
        // Draw the highlight
        Point2D center = new Point2D.Float((float)HIGHLIGHT_SIZE / 2.0f,
                (float)HIGHLIGHT_SIZE / 2.0f);
        float radius = (float)HIGHLIGHT_SIZE / 2.0f;
        float[] dist = {0.0f, .85f};
        Color[] colors = {Color.white, new Color(255, 255, 255, 0)};
        RadialGradientPaint paint = new RadialGradientPaint(center, radius,
                dist, colors);
        g2d.setPaint(paint);
        g2d.fillOval(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE);
        g2d.dispose();
    }
    
    /**
	 * 
	 * @param g the g to set 
	 */
    @Override
    protected void paintComponent(Graphics g) 
    {
        super.paintComponent(g);
        g.drawImage(highlight, getWidth()/4, getHeight()/4, null);
    }  
    
    static final int HIGHLIGHT_SIZE = 18;
    BufferedImage highlight = new BufferedImage(
            HIGHLIGHT_SIZE, HIGHLIGHT_SIZE, BufferedImage.TYPE_INT_ARGB);
    
    private static final long serialVersionUID = 2390531593074368696L;
}
